//
//  DXWTextField.m
//  BuDeJie
//
//  Created by 淡馨慰 on 16/8/7.
//  Copyright © 2016年 淡馨慰. All rights reserved.
//

#import "DXWTextField.h"

@implementation DXWTextField

//重新设置文本框的占位文字颜色
- (void)awakeFromNib
{
    //1.开始编辑
    self.tintColor = [UIColor whiteColor];
    
    [self addTarget:self action:@selector(textBeginEditing) forControlEvents:UIControlEventEditingDidBegin];
    
    //2.结束编辑
    [self addTarget:self action:@selector(textEndEditing) forControlEvents:UIControlEventEditingDidEnd];
    
    
    /**
     *  KVC快速设置占位文字
     */
    UILabel *placeholderLabel = [self valueForKey:@"placeholderLabel"];
    placeholderLabel.textColor = [UIColor lightGrayColor];
    
    [super awakeFromNib];
}

- (void)textBeginEditing
{
    /**
     *  KVC快速设置占位文字
     */
    UILabel *placeholderLabel = [self valueForKey:@"placeholderLabel"];
    placeholderLabel.textColor = [UIColor whiteColor];
}
- (void)textEndEditing
{
    /**
     *  KVC快速设置占位文字
     */
    UILabel *placeholderLabel = [self valueForKey:@"placeholderLabel"];
    placeholderLabel.textColor = [UIColor lightGrayColor];
}

//-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
//{
//    if (controlEvents == UIControlEventEditingDidBegin) {
//        NSDictionary *attr = @{
//                               NSForegroundColorAttributeName : [UIColor whiteColor]
//                               };
//        self.attributedPlaceholder = [[NSAttributedString alloc]initWithString:self.placeholder attributes:attr];
//    }
//    else if (controlEvents == UIControlEventEditingDidEnd)
//    {
//    NSDictionary *attr = @{
//                           NSForegroundColorAttributeName : [UIColor redColor]
//                           };
//    self.attributedPlaceholder = [[NSAttributedString alloc]initWithString:self.placeholder attributes:attr];
//    }
//
//}

@end
